package person.drf.shop.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import person.drf.common.utils.R;
import person.drf.shop.search.service.MallSearchService;
import person.drf.shop.search.vo.SearchParm;
import person.drf.shop.search.vo.SearchResult;


@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String listPage(SearchParm searchParm, Model model){

        // 1. 根据传递过来的页面查询条件，去ES中检索商品
        SearchResult result =  mallSearchService.search(searchParm);

        model.addAttribute("result",result);

        return "list";
    }

    @ResponseBody
    @GetMapping("/list")
    public R testlist(SearchParm searchParm){

        // 1. 根据传递过来的页面查询条件，去ES中检索商品
        SearchResult result =  mallSearchService.search(searchParm);



        return R.ok().setData(result);
    }


}


